package com.gexiaobao.pigeon.ui.adapter

import android.annotation.SuppressLint
import android.graphics.Color
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.MyShopOrderListResponse
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.gexiaobao.pigeon.app.util.SettingUtil
import com.gexiaobao.pigeon.app.util.Util
import com.gexiaobao.pigeon.databinding.ItemMyGoodsMineOrderBinding
import com.makeramen.roundedimageview.RoundedImageView

/**
 * @author: hxw
 * @date  : 2023/2/2
 * @desc  :
 */
class MyGoodsItemAdapter(data: ArrayList<MyShopOrderListResponse.ListBean.ListGoods>) :
    BaseQuickAdapter<MyShopOrderListResponse.ListBean.ListGoods, DataBindBaseViewHolder>(R.layout.item_my_goods_mine_order, data) {

    @SuppressLint("SetTextI18n", "NotifyDataSetChanged")
    override fun convert(holder: DataBindBaseViewHolder, item: MyShopOrderListResponse.ListBean.ListGoods) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemMyGoodsMineOrderBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val ivItemMyGoodsOrderImageIcon = holder.getView<RoundedImageView>(R.id.ivItemMyGoodsOrderImageIcon)
        ImageLoaderManager.loadRoundImageOrEmpty(context, item.specImg, ivItemMyGoodsOrderImageIcon, 10, R.drawable.shop_product_def)

        val tvPrice = holder.getView<AppCompatTextView>(R.id.itemPrice)
        val totalPrice = Util.mul(item.salePrice.toString(), item.amount.toString())
        SettingUtil.setPrice(totalPrice, tvPrice, 50, Color.BLACK)
    }
}